﻿using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class TargetSelect_LastHitSelf : TargetSelect
    {
        public override ETargetSelectType selectType => ETargetSelectType.LastHitSelf;

        public override void TrySelect(SelectParam rParam, LVector2 rSelfPos, ref List<Unit> rTargets)
        {
            var rCustom = this.self.GetComponent<CustomPropertyComponent>(ETComponentType.CustomPropertyComponent);
            var rUID = rCustom.GetProperty<long>(ECustomProperty.LastHitSelf);
            if (this.self.battle.playCtrl.unitCtrl.TryGetUnit(rUID, out var rUnit))
            {
                rTargets.Add(rUnit);
            }
        }

        public override void Free()
        {
            ClassPool.Put(this);
        }
    }
}